package com.qiwx.pigeon.adapter.home;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.qiwx.pigeon.R;
import com.qiwx.pigeon.Utils.DateTimeUtils;
import com.qiwx.pigeon.base.Constant;
import com.qiwx.pigeon.data.CageStatusConfig;
import com.qiwx.pigeon.data.vo.CageBeanVo;
import com.qiwx.pigeon.data.vo.PairBean;
import com.qiwx.pigeon.data.vo.PigeonPiarBean;

import java.util.List;

/**
 * @description
 * @Author qiwx
 * @Date 2020-04-05 13:11
 * 待配对Adapter
 **/
public class PigeonPairAdapter extends BaseQuickAdapter<PairBean, BaseViewHolder> {

    ICageInterface iPigeonPairInterface;

    public PigeonPairAdapter(int layoutResId, List<PairBean> data) {
        super(layoutResId, data);
    }

    public void setIPigeonPairInterface(ICageInterface iPigeonPairInterface) {
        this.iPigeonPairInterface = iPigeonPairInterface;
    }

    @Override
    protected void convert(BaseViewHolder holder, PairBean bean) {
        holder.setText(R.id.txt_c_number, bean.getC_number() + "");
        holder.setText(R.id.txt_status, CageStatusConfig.getShowByStatus(bean.getStatus()));
        holder.setText(R.id.txt_pddate, bean.getPd_date() == null ? "--" : bean.getPd_date());
        holder.setText(R.id.txt_pdtimes, bean.getPd_times() + "");
        int days = DateTimeUtils.getLayEggDaysFromToday(bean.getPd_date());
        if (bean.getPd_times() >= 2) {
            holder.setTextColor(R.id.txt_c_number, getContext().getResources().getColor(R.color.text_color_red));
        } else if (days >= 20) {
            holder.setTextColor(R.id.txt_c_number, getContext().getResources().getColor(R.color.text_color_blue));
        } else {
            holder.setTextColor(R.id.txt_c_number, getContext().getResources().getColor(R.color.text_color_black));
        }
        if (bean.getStatus() == CageStatusConfig.STATUS_PD) {
            holder.setText(R.id.btn_opreate, "确认成功");
            // holder.setVisible(R.id.btn_opreate,false);
        } else {
            holder.setText(R.id.btn_opreate, "配对");
//            holder.setVisible(R.id.btn_opreate,true);
        }
        holder.findView(R.id.btn_opreate).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (iPigeonPairInterface != null) {
                    iPigeonPairInterface.onSelectId(holder.getAdapterPosition(), bean.getC_id(), 0);
                }

            }
        });
        holder.findView(R.id.btn_kl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (iPigeonPairInterface != null) {
                    iPigeonPairInterface.onSelectId(holder.getAdapterPosition(), bean.getC_id(), 1);
                }

            }
        });


    }
}
